var e = require("../../../../../@babel/runtime/helpers/regeneratorRuntime"),
  n = require("../../../../../@babel/runtime/helpers/asyncToGenerator"),
  r = require("../../../../../store/index"),
  i = require("../../../../../utils/helper/recharge/index"),
  o = require("../../../../../utils/tools/common/index");
Component({
  useStore: function (e) {
    return {
      userInfo: e.user.userInfo
    }
  },
  properties: {
    show: {
      type: Boolean,
      value: !1
    },
    id: {
      type: Number,
      value: 0
    },
    isAgree: {
      type: Boolean,
      value: !1
    },
    isShowRightNowPay: {
      type: Boolean,
      value: !0
    },
    defaultSelectedIndex: {
      type: Number || null,
      value: null
    },
    needPoints: {
      type: Number,
      value: 0
    }
  },
  data: {
    value: "",
    approveRemark: "",
    visible: !1,
    rechargeList: [],
    selectedItem: {
      id: null,
      integral: 0,
      price: 0,
      text: ""
    },
    amt: 0,
    selectedRow: 0
  },
  observers: {
    show: function (e) {
      // e && this.requestRechargeList()
    }
  },
  methods: {
    onTap: function () {
      this.setData({
        visible: !0
      })
    },
    onClose: function () {
      this.triggerEvent("close")
    },
    requestRechargeList: function () {
      var r = this;
      return n(e().mark((function n() {
        var i, s, a, l, c, u;
        return e().wrap((function (e) {
          for (;;) switch (e.prev = e.next) {
            case 0:
              return a = r.data.defaultSelectedIndex, wx.showLoading({
                title: "加载中"
              }), e.next = 4, $.request["POST/coin/recharge-ready?source=XCX"]().catch((function () {
                r.onClose()
              }));
            case 4:
              if (l = e.sent, c = t(l, 1), u = c[0], wx.hideLoading(), 200 === (null == u ? void 0 : u.code)) {
                e.next = 9;
                break
              }
              return e.abrupt("return", ($.msg(null == u ? void 0 : u.msg), void r.onClose()));
            case 9:
              r.setData({
                rechargeList: (0, o.toSplitArr)(null == u || null === (i = u.content) || void 0 === i ? void 0 : i.config_list, 3),
                selectedItem: null == u || null === (s = u.content) || void 0 === s ? void 0 : s.config_list[null != a ? a : 0]
              });
            case 10:
            case "end":
              return e.stop()
          }
        }), n)
      })))()
    },
    agree() {
      wx.showLoading({
        title: '提交中...',
      })
      console.log(this.data.approveRemark)
      console.log(this.data.isAgree)
      if (!this.data.isAgree) {
        if (!this.data.approveRemark) {
          wx.showToast({
            icon: 'error',
            title: '请填写驳回理由'
          })
          return false
        }

      }
      var data = {
        status: this.data.isAgree ? 3 : 4,
      }
      if (!this.data.isAgree) {
        data.approveRemark = this.data.approveRemark
      }
      console.log(this)
      var that = this;
      $.request['POST/business/engineering/log/approve/' + this.id]({
        status: this.data.isAgree ? 3 : 4,
        approveRemark: this.data.approveRemark
      }).then(res => {
        res = res[0]
        if (res.code == 20002) {
          wx.showToast({
            icon: 'none',
            title: '提交成功'
          })
          that.triggerEvent("approval", true);
          setTimeout(() => {
            this.setData({
              show: false
            })
          }, 500);

        } else {
          that.triggerEvent("approval", false);
          wx.showToast({
            icon: 'error',
            title: res.msg
          })
        }
      }).finally(() => {
        wx.hideLoading()
      })
    },
    onPayment: function () {
      var e = this,
        t = this.data.selectedItem;
      t.price && (wx.showLoading({
        title: "加载中",
        mask: !0
      }), (0, i.recharge)(t.price).then((function () {
        wx.hideLoading();
        var n = e.data.userInfo.coin_balance + t.coin;
        (0, r.dispatch)(r.actions.userActions.setUserInfo({
          coin_balance: n
        })), $.msg("支付成功"), e.triggerEvent("close")
      })).catch((function (e) {
        wx.hideLoading(), "requestPayment:fail cancel" === (null == e ? void 0 : e.errMsg) ? $.msg("您取消了支付") : $.msg("支付失败")
      })))
    },
    onSelectItem: function (e) {
      var t = e.currentTarget.dataset,
        n = t.item,
        r = t.rowIndex;
      this.setData({
        selectedItem: n,
        selectedRow: r
      })
    }
  }
});